#pragma once
#include<QWidget>
#include<QKeyEvent>
#include<bars.h>
#include<bird.h>
#include<scorenum.h>
#include<ground.h>
#include<gameover.h>
#include<replay.h>
#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia>
class flappyBird :public QWidget
{
   Q_OBJECT
public:
    flappyBird(int c_back,int c_bird,int c_bar,QWidget *parent=nullptr);
    void drawObjects(QPainter *);
    void moveObjects();
    void startGame();
    void pauseGame();
    void stopGame();
    void checkCollison();
    void checkScore();
    void die();
    void playWingSound();
    void playSound(int);
    //~flappyBird();
protected:
    void paintEvent(QPaintEvent *);
    void keyPressEvent(QKeyEvent *);
    void mousePressEvent(QMouseEvent*);
private:
    int scores;
    int x;
    QTimer* timerId;
    QTimer* stateTimer;
    QTimer* wingTimer;
    QTimer* updateTimer;
    QTimer* dieTimer;
    static const int DELAY = 10;
    static const int NUM_B=5;
    static const int BOTTOM_EDGE = 400;
    Bars *bars[NUM_B+1];
    Bird *bird;
    int state;
    bool add_once;
    scoreNum *scoreBoard;
    int lastPipe;
    ground *bottom;
    overBoard* gameoverBoard;
    Replay * playBtn;
    void resetGame();
    int colorOfBars;
    int backGround;

    QMediaPlayer *media;
    QMediaPlayer *media2;
    enum{s_wing=0,s_point=1,s_die=2,s_hit=3,s_sw=4};
    QMediaPlaylist *playList;
    QMediaPlaylist *playList_wing;
    int isFlag;
    bool isHit;
};
